 # @Author: Cjuicy 
# @Date: 2022-03-23 09:37:21 
# @Last Modified by:   Cjuicys 
# @Last Modified time: 2022-03-23 09:37:21 


from logging import root
import pymysql

dbhost='localhost'
dbuser='root'
dbpass='12345678'
dbname='order_info'

'''连接数据库'''
try:
    db=pymysql.connect(host=dbhost,user=dbuser,password=dbpass,database=dbname)
    print("数据库连接成功")
except pymysql.Error as e:
    print("数据库连接失败："+str(e))

cursor = db.cursor()

''' 插入字段 '''
def insert_order_info(order_info):
    # 对有字符串的内容，添加双引号，这样才能够读取   -1是应为要插入时间，时间不能加双引号
    for i in range(len(order_info)-1):
        if order_info[i] != 'null':
            order_info[i] = "'" + order_info[i] + "'"
    order_info = ','.join(order_info)
    
    #数据库文字
    sql = "INSERT INTO `order_info`.`OrderInfo`VALUES(%s);"%(order_info)
    # print(sql)
    cursor.execute(sql)
    db.commit
    print('插入成功')


''' 显示插入的字段 '''
def select_order_info(): 
    select = "SELECT * FROM order_info.OrderInfo;"
    cursor.execute(select)
    alldata = cursor.fetchall()
    print(alldata)





